package com.xiaoqi.store.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author Rookie Coder
 * @Description 登录拦截器
 * @Date
 **/
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    /*
    * @Author xiaoqi
    * @Description  验证是否登录
    * @return
    **/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (request.getSession().getAttribute("uid") == null){
                response.sendRedirect("/web/login.html");
                return false;
        }
        log.info("用户已登录"+request.getSession().getAttribute("uid"));
        return true;
    }

}
